package com.xywy.beautyand.ADAPTER;

import java.util.List;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.xywy.beautyand.R;
import com.xywy.beautyand.base.BasicAdapter;
import com.xywy.beautyand.bean.QuestionReplay;
import com.xywy.beautyand.util.ImageLoader.ImageCallback;

/**
 * *****************************************
 * 
 * @Title: QuestionDetailAdapter.java
 * @Package com.xywy.performgirlsandroid.adapter
 * @Description: TODO(问题详情适配器)
 * @author smz
 * @date 2015-1-4 上午11:39:27
 * @version V1.0
 ******************************************* 
 */
public class QuestionDetailAdapter extends BasicAdapter<QuestionReplay> {
	private LayoutInflater inflater;

	public QuestionDetailAdapter(Context context, List<QuestionReplay> list) {
		super(context, list);
		this.inflater = LayoutInflater.from(context);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		viewholder holder;
		if(convertView==null){
			holder=new viewholder();
			convertView=inflater.inflate(R.layout.item_doctor_detail, null);
			holder.head=(ImageView) convertView.findViewById(R.id.head);
			holder.name=(TextView) convertView.findViewById(R.id.name);
			holder.linear1=(LinearLayout) convertView.findViewById(R.id.linear1);
			holder.star1=(ImageView) convertView.findViewById(R.id.star1);
			holder.star2=(ImageView) convertView.findViewById(R.id.star2);
			holder.star3=(ImageView) convertView.findViewById(R.id.star3);
			holder.star4=(ImageView) convertView.findViewById(R.id.star4);
			holder.star5=(ImageView) convertView.findViewById(R.id.star5);
			holder.doctor_honor=(TextView) convertView.findViewById(R.id.doctor_honor);
			holder.replay_number=(TextView) convertView.findViewById(R.id.replay_number);
			holder.doctor_replay_time=(TextView) convertView.findViewById(R.id.doctor_replay_time);
			holder.doctor_replay_text=(TextView) convertView.findViewById(R.id.doctor_replay_text);
			holder.im1=(ImageView) convertView.findViewById(R.id.im1);
			convertView.setTag(holder);
		}else{
			holder=(viewholder)convertView.getTag();
		}
		
		String url=list.get(position).getDocAvatar();
		String  name=list.get(position).getDocName();
		String docLevel=list.get(position).getDocLevel();
		String dnum=list.get(position).getDnum();
		int grade=list.get(position).getGrade();
		String docRepliedContent=list.get(position).getDocRepliedContent();
		String repTime=list.get(position).getRepTime();
		
		
		Drawable cachedImage = loader.loadDrawable(url,
				holder.head, new ImageCallback() {

					@Override
					public void imageLoaded(Drawable imageDrawable,
							ImageView imageView, String imageUrl) {
						if (imageView != null && imageDrawable != null) {
							imageView.setBackgroundDrawable(imageDrawable);
						}
					}
				});
    	
    	if(cachedImage==null){
    		holder.head.setBackgroundResource(R.drawable.head);
    	}else{
    		holder.head.setBackgroundDrawable(cachedImage);
    	}
    	
    	holder.name.setText(name);
    	if(grade==0){
    		holder.linear1.setVisibility(View.INVISIBLE);
    	}else{
    		holder.linear1.setVisibility(View.VISIBLE);
    		if(grade==1){
    		holder.star1.setBackgroundResource(R.drawable.entiny_star);
    		holder.star2.setBackgroundResource(R.drawable.empty_star);
    		holder.star3.setBackgroundResource(R.drawable.empty_star);
    		holder.star4.setBackgroundResource(R.drawable.empty_star);
    		holder.star5.setBackgroundResource(R.drawable.empty_star);
    		
    		}else if(grade==2){
    			
    			holder.star1.setBackgroundResource(R.drawable.entiny_star);
        		holder.star2.setBackgroundResource(R.drawable.entiny_star);
        		holder.star3.setBackgroundResource(R.drawable.empty_star);
        		holder.star4.setBackgroundResource(R.drawable.empty_star);
        		holder.star5.setBackgroundResource(R.drawable.empty_star);
    		}else if(grade==3){
    			
    			holder.star1.setBackgroundResource(R.drawable.entiny_star);
        		holder.star2.setBackgroundResource(R.drawable.entiny_star);
        		holder.star3.setBackgroundResource(R.drawable.entiny_star);
        		holder.star4.setBackgroundResource(R.drawable.empty_star);
        		holder.star5.setBackgroundResource(R.drawable.empty_star);
    		}else if(grade==4){
    			
    			holder.star1.setBackgroundResource(R.drawable.entiny_star);
        		holder.star2.setBackgroundResource(R.drawable.entiny_star);
        		holder.star3.setBackgroundResource(R.drawable.entiny_star);
        		holder.star4.setBackgroundResource(R.drawable.entiny_star);
        		holder.star5.setBackgroundResource(R.drawable.empty_star);
    		}else if(grade==5){
    			
    			holder.star1.setBackgroundResource(R.drawable.entiny_star);
        		holder.star2.setBackgroundResource(R.drawable.entiny_star);
        		holder.star3.setBackgroundResource(R.drawable.entiny_star);
        		holder.star4.setBackgroundResource(R.drawable.entiny_star);
        		holder.star5.setBackgroundResource(R.drawable.entiny_star);
    		}

    	}
    	
    	holder.doctor_honor.setText(docLevel);
    	holder.replay_number.setText("已回答"+dnum+"问题");
    	holder.doctor_replay_time.setText(repTime);
    	holder.doctor_replay_text.setText(docRepliedContent);
    	
    	if(position==0){
    		holder.im1.setVisibility(View.VISIBLE);
    	}else{
    		holder.im1.setVisibility(View.INVISIBLE);
    	}
		
		return convertView;
	}

	private class viewholder {
		
		private ImageView im1;
		private ImageView head;
		private TextView name;
		private LinearLayout linear1;
		private ImageView star1;
		private ImageView star2;
		private ImageView star3;
		private ImageView star4;
		private ImageView star5;
		private TextView doctor_honor;
		private TextView replay_number;
		private TextView doctor_replay_time;
		private TextView doctor_replay_text;
	}

}
